import { ConfigEnv, defineConfig, loadEnv, UserConfigExport } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
  // 获取根路径
  const root = process.cwd();
  // 获取环境变量文件的内容
  const envInfo = loadEnv(mode, root);
  return {
    plugins: [vue()],
    resolve: {
      alias: {
        '@': resolve(__dirname, "src") //设置别名
      }
    },
    server: {
      host: 'localhost',
      port: Number(envInfo.VITE_APP_PORT), // 使用
      open: false,
    },
  };
};
